<?php
defined('_JEXEC') or die(); 
JHTML::_('behavior.tooltip'); 

$listOrder	= @$this->lists['order'];
$listDirn	= @$this->lists['order_Dir'];
$user = &JFactory::getUser();
?>
<script type="text/javascript">
	function submitform(pressbutton){
		var form = document.adminForm ;
	   	if (pressbutton)
	    {
	   	    form.task.value=pressbutton ;
	   	}
		if ((pressbutton=='add') ||(pressbutton=='publish') ||(pressbutton=='unpublish')|| (pressbutton=='remove')||(pressbutton=='send_mail_verify') || (pressbutton=='send_mail_renew') || (pressbutton=='send_mail_birth'))
		{
			form.controller.value="profile" ;
		}
		if(pressbutton=='export'){
			//alert("<?php echo(__FILE__.__LINE__);?>");
		}
		form.submit();
	}
	
	Joomla.submitbutton = function(pressbutton){
		if (pressbutton == 'remove') {
			if(confirm('Are you sure ?')){
				submitform( pressbutton );
			}
		}else{
			submitform( pressbutton );
		}
	}
	
</script>

<form  id="adminForm" 
	action="<?php echo JRoute::_("index.php?option=com_wrd&controller=profile")?>" 
	method="post" name="adminForm" >
    <div id="editcell">
    	    <?php if (!empty( $this->sidebar)) : ?>
	<div id="j-sidebar-container" class="span2">
		<?php echo $this->sidebar; ?>
	</div>
	<div id="j-main-container" class="span10">
	<?php else : ?>
		<div id="j-main-container">
	<?php endif;?>
		<br clear="all">
		<div class="alert">
		<table style='margin-bottom:5px'>
			<tr>
				<td width="352" align="left" valign="top" style='border-right: 1px solid #d0d0d0;'>
					<table>
						<tr>
							<td width='100px' valign="top">Look for:<br><?php echo $this->lists['searchFillter'] ; ?>
							
								<br><?php echo JText::_('<b>=</b>'); ?><br>
								<input type="text" name="search" id="search" value="<?php echo $this->search ?>" class="text_area" />
								<input class='go' title='Go' type='button' value="Go" onclick="this.form.submit();" />
								<input class='go' title='Reset' type='button' value="Reset" onclick="reset_all();" />
								<script>
									function reset_all(){
										var form = document.adminForm;
										form.searchfillter.value='';
										form.search.value='';
										form.datefillter.value = 0;
										form.profilefillter.value=0;
										form.pick_up_at.value='0' ;
										form.byfrom.value=1900; 
										form.bmfrom.value=1; 
										
										form.bdfrom.value=1;
										form.byto.value=<?php echo date("Y"); ?>; 
										form.bmto.value=12; 
										form.bdto.value=31;
										form.submit();
								}
								</script>
							</td>
						</tr>
					</table>
				</td>
				
				<td valign="top" style='border-right: 1px solid #d0d0d0;'>
					<table>
						<tr>
							
							<td><?php echo 'Look for Card status = ' ; ?><br>
							<?php 
								echo $this->lists['profilefillter'] ;  
							?>
							<br><?php echo 'with ' ; ?><br>
							<?php echo $this->lists['filter_pick_up_outlet'] ; ?><br>
							<input class='go' title='Go' type='button' value="Go" onclick="this.form.submit();" /></td>
						</tr>
					</table>
				</td>
				<td valign="top">
					<table id="tbl_test">
						<tr>
							
							<td valign='top' width='70px'>
								Look For :<br>
								<?php echo $this->lists['datefillter']; ?>
								From:
								
								<?php 
									echo $this->lists['byfrom'] ;
									echo $this->lists['bmfrom'] ;
									echo $this->lists['bdfrom'] ; 
								?><br/>To:<br/>
								<?php 
									echo $this->lists['byto'] ; 
									echo $this->lists['bmto'] ;
									echo $this->lists['bdto'] ;
								?>
							<br>
							<input onclick="checkBirthdayFilter()" title='Go' type='button' value="Go" id="search_birth" class="go" />
							<script>
								function checkBirthdayFilter(){
									var form = document.adminForm ;
									/*
									if(form.byfrom.value !='' && form.byfrom.value != '0'  && form.byfrom.value != '0000' && form.byfrom.value != 0){ 
										var byfrom  = parseInt(form.byfrom.value) ;
									}else{
										var byfrom = '0000' ;
									}
									var bmfrom = parseInt(form.bmfrom.value) ;
									var bdfrom = parseInt(form.bdfrom.value) ;
									if(form.byto.value != '' && form.byto.value != '0' && form.byto.value != '0000' && form.byto.value != 0 ){
										var byto  = parseInt(form.byto.value) ;
									}else{
										<?php 
											$cur_year =  explode('-', date('Y-m-d')) ;
										?>
										var byto  = '<?php echo ($cur_year[0] + 1) ; ?>' ;
									}
									var bmto = parseInt(form.bmto.value);
									var bdto  = parseInt(form.bdto.value);
									var from_day = new Date(byfrom, bmfrom, bdfrom);
									var to_day = new Date(byto, bmto, bdto);
									
									if(to_day < from_day){
										
										alert('"From date or To date is not correct."') ;
										return false ;
									}
									*/
									form.controller.value = "profile" ;
									form.submit();
								}
							</script>
							</td>
						</tr>
					</table>
				</td>
			</tr>
		</table>
		</div>
		<table class="table table-striped adminlist">
		<thead>
			<tr>
				<th width="5%">
					<?php echo JHtml::_('grid.checkall'); ?>
				</th>
				<th class="title" width="5%"><?php echo JHTML::_('grid.sort',  'Gender', 'p.prefix', $listDirn, $listOrder ); ?></th>
				<th class="title" width="20%"><?php echo JHTML::_('grid.sort',  'Name', 'p.l_name', $listDirn, $listOrder ); ?></th>
               	<th class="title" width="10%"><?php echo JHTML::_('grid.sort',  'Member ID', 'p.member_id', $listDirn, $listOrder ); ?></th>
               	<th class="title" width="9%"><?php echo JHTML::_('grid.sort',  'Point', 'p_o_u', $listDirn, $listOrder );?></th>
                <?php if($this->user->authorise('wrd.profile.phone.col', 'com_wrd')) :?>
                <th nowrap="nowrap" width="10%"><?php echo JHTML::_('grid.sort',  'Phone', 'p.phone', $listDirn, $listOrder ); ?></th>
                <?php else: ?>
				<th nowrap="nowrap" width="10%"><?php echo JHTML::_('grid.sort',  'Email', 'p.p_email', $listDirn, $listOrder ); ?></th>
				 <?php endif; ?>
				 
				<?php if($this->user->authorise('wrd.profile.job.col', 'com_wrd')) :?>
				<th nowrap="nowrap" width="9%"><?php echo JHTML::_('grid.sort',  'Job', 'p.job', $listDirn, $listOrder ); ?></th> 
				<?php endif; ?>
				
				<?php if($this->user->authorise('wrd.profile.company.col', 'com_wrd')) :?>
				<th nowrap="nowrap" width="10%"><?php echo JHTML::_('grid.sort',  'Company name', 'p.company_name', $listDirn, $listOrder ); ?></th>
				<?php endif; ?>
				
				<th nowrap="nowrap" width="9%"><?php echo JHTML::_('grid.sort',  'Day of birth', 'p.dob', $listDirn, $listOrder ); ?></th>
				<th nowrap="nowrap" width="9%"><?php echo JHTML::_('grid.sort',  'Last visit', 'outlet.code', $listDirn, $listOrder ); ?></th>
				
				<?php if($this->user->authorise('wrd.profile.visitdate.col', 'com_wrd')) :?>
				<th nowrap="nowrap" width="9%"><?php echo JHTML::_('grid.sort',  'Visit date', 'p.outlet_date', $listDirn, $listOrder ); ?></th>
				<?php endif; ?>
				
				<?php if($this->user->authorise('wrd.profile.createddate.col', 'com_wrd')) :?>
				<th nowrap="nowrap" width="8%"><?php echo JHTML::_('grid.sort',  'Created Date', 'p.created_date', $listDirn, $listOrder ); ?></th>
				<?php endif; ?>
				
				<?php if($this->user->authorise('wrd.profile.createdby.col', 'com_wrd')) :?>
				<th nowrap="nowrap" width="10%"><?php echo JHTML::_('grid.sort',  'Created By', 'u.name', $listDirn, $listOrder ); ?></th>
				<?php endif; ?>
				<th nowrap="nowrap" width="18%"><?php echo JHTML::_('grid.sort',  'Series No', 'p.serial_no', $listDirn, $listOrder ); ?></th>
			</tr>
		</thead>
		<tbody>
		<?php
        $k = 0;
		$n= count( $this->items );
		for ($i=0; $i < $n; ++$i):
			$row = &$this->items[$i];
			$checked 	= JHTML::_('grid.checkedout',   $row, $i);
            $canChange	= $user->authorise('core.edit.state', 'com_wrd.profile.'.$row->id);
			$published 	= JHTML::_('jgrid.published', $row->published, $i,'profile.', $canChange,'cb');
		?>
			<tr align="center" class="<?php echo "row$k"; ?>"  >
           
				<td align="center">
					<?php echo $checked; ?>
				</td>
				<td align="center">
					<?php echo $row->prefix; ?>
				</td>
				<td align="center">
				
					<a href="index.php?option=com_wrd&controller=profile&id=<?php echo $row->id;?>&layout=form">
						<?php 
							if(!empty($row->name_on_card)){
								echo $row->name_on_card ;
							}else{
								if(!empty($row->l_name) || !empty($row->f_name)){
									echo  $row->full_name ; 
								}else{
									if(!empty($row->name)){
										echo  $row->name ; 
									}else{
										echo $row->email;
									}
								}
							}
						?>
					</a>
				</td>
				<td align="center">
					<?php echo $row->member_id; ?>
				</td>
				<td align="center">
					<?php 
						echo '<a href="'.JURI::root().'administrator/index.php?option=com_wrd&controller=profile&id='.$row->id.'&layout=form&tab=point">'.number_format($row->p_o_u,0,'.','.').'</a>';	
					?>
				</td>
				<?php if($this->user->authorise('wrd.profile.phone.col', 'com_wrd')) :?>
				<td align="center">
					<?php echo $row->phone; ?>
				</td>
				<?php else: ?>
				<td align="left">
					<?php echo $row->p_email; ?>
				</td>
				<?php endif; ?>
				
				<?php if($this->user->authorise('wrd.profile.job.col', 'com_wrd')) :?>
				<td align="center">
					<?php 
						if($row->job != 'other'){
							if(!empty($row->job_name)){ 
								echo $row->job_name;
							}
						}else{
							echo $row->o_job ;
						} 
					?>
				</td>
				<?php endif; ?>
				<?php if($this->user->authorise('wrd.profile.company.col', 'com_wrd')) :?>
				<td align="center">
					<?php echo $row->company_name; ?>
				</td>
				<?php endif; ?>
				<td align="center">
					<?php
						$dob = explode('-', $row->dob ) ;
						echo $dob[2]."-".$dob[1]."-".$dob[0]; 
					?>
				</td>
				<td align="center">
					<?php echo $row->name; ?>
				</td>
				<?php if($this->user->authorise('wrd.profile.visitdate.col', 'com_wrd')) :?>
				<td align="center">
					<?php echo $row->outlet_date != '0000-00-00 00:00:00' ? date('d-m-Y H:m:s',strtotime($row->outlet_date)) : ''; ?>
				</td>
				<?php endif; ?>
				<?php if($this->user->authorise('wrd.profile.createddate.col', 'com_wrd')) :?>
				<td align="center">
					<?php echo $row->created_date != '0000-00-00' ? date('d-m-Y',strtotime($row->created_date)) : ''; ?>
				</td>
				<?php endif; ?>
				<?php if($this->user->authorise('wrd.profile.createdby.col', 'com_wrd')) :?>
				<td align="center">
					<?php 
						echo $row->created_per;	
					?>
				</td>
				<?php endif; ?>
				<?php if($this->user->authorise('wrd.profile.status.col', 'com_wrd')) :?>
				<td align="center">
					<?php 
						echo $row->serial_no;
						
					?>
				</td>
				<?php endif; ?>
			</tr>
			<?php
            $k = 1 - $k;
		endfor ;
		?>
		</tbody>

		<tfoot>
			<tr>
                <td colspan="16">
                    <?php
                         echo $this->pagination->getListFooter();
                    ?>
                </td>
			</tr>
		</tfoot>
		</table>
	</div>
	<input type="hidden" name="controller" value="profile" />
	<input type="hidden" name="option" value="com_wrd" />
	<input type="hidden" name="task" value="" />
	<input type="hidden" name="boxchecked" value="0" />
    <input type="hidden" name="filter_order" value="<?php echo $this->lists['order']; ?>" />
    <input type="hidden" name="filter_order_Dir" value="<?php echo $this->lists['order_Dir']; ?>" />
	<?php echo JHTML::_( 'form.token' ); ?>
</form>